package com.hxd.otc.module.convenience.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/12/13 0013.
 * description ${充值记录Adpater}
 */
public class PrepaidRechargeHistoriesAdapter extends BaseAdapter<RecyclerView.ViewHolder, String> {
    public static final int ITEM_TYPE_NOR = 0;
    public static final int ITEM_TYPE_FOOTER = 1;


    public PrepaidRechargeHistoriesAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == ITEM_TYPE_FOOTER) {
            onBindFooterHolder((FooterHolder) holder);
        } else {
            onBindHistoriesHolder((HistoriesHolder) holder, position);
        }
    }

    private void onBindHistoriesHolder(HistoriesHolder holder, int position) {
        String item = getItem(position);
        holder.tvContent.setText(item);
    }

    private void onBindFooterHolder(FooterHolder holder) {
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == ITEM_TYPE_FOOTER) {
            return new FooterHolder(mInflater.inflate(R.layout.item_hostories_footer, parent, false));
        } else {
            return new HistoriesHolder(mInflater.inflate(R.layout.item_hostories, parent, false));
        }

    }

    @Override
    public int getItemViewType(int position) {
        return position == getItems().size() ? ITEM_TYPE_FOOTER : ITEM_TYPE_NOR;
    }

    @Override
    protected int getFooterLayoutCount() {
        return 1;
    }

    static class HistoriesHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_content)
        TextView tvContent;

        HistoriesHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    static class FooterHolder extends RecyclerView.ViewHolder {
        FooterHolder(View itemView) {
            super(itemView);
        }
    }
}
